<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>AdminLTE 2 | General Form Elements</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" th:href="@{/adminlte/bower_components/bootstrap/dist/css/bootstrap.min.css}">
    <!-- Font Awesome -->
    <link rel="stylesheet" th:href="@{/adminlte/bower_components/font-awesome/css/font-awesome.min.css}">
    <!-- Ionicons -->
    <link rel="stylesheet" th:href="@{/adminlte/bower_components/Ionicons/css/ionicons.min.css}">
    <!-- Theme style -->
    <link rel="stylesheet" th:href="@{/adminlte/css/AdminLTE.min.css}">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" th:href="@{/adminlte/css/skins/_all-skins.min.css}">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Google Font -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content">
    <!-- Horizontal Form -->
    <div class="box">
        <div class="box-header with-border">
            <h3 class="box-title" th:text="${title}"></h3>
        </div>
        <!-- /.box-header -->
        <!-- form start -->
        <form class="form-horizontal" action="/User/updateMerchant" method="post" th:object="${user}" enctype="multipart/form-data">
            <div class="box-body">
                <input type="hidden" class="form-control" th:field="*{id}">
                <div class="form-group">
                    <label class="col-sm-4 control-label">姓名</label>

                    <div class="col-sm-4">
                        <input type="text" class="form-control" th:field="*{name}">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-4 control-label">昵称</label>

                    <div class="col-sm-4">
                        <input type="text" class="form-control" th:field="*{nickname}">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-4 control-label">邮箱</label>

                    <div class="col-sm-4">
                        <input type="text" class="form-control" th:field="*{email}">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-4 control-label">手机号码</label>

                    <div class="col-sm-4">
                        <input type="text" class="form-control" th:field="*{phone}">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-4 control-label">性别</label>

                    <div class="col-sm-4">
                        <input type="text" class="form-control" th:field="*{sex}">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-4 control-label">生日</label>

                    <div class="col-sm-4">
                        <input type="text" class="form-control" th:field="*{birthday}">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-4 control-label">用户类型</label>

                    <div class="col-sm-4">
                        <input type="text" class="form-control" th:field="*{type}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="col-sm-4 control-label">头像</label>
                    <input type="hidden" th:field="*{head}" id="head">
                    <div class="col-sm-4" id="img">
                        <img style="width: 300px;" th:src="'/myFile/img/userHeadPic/' + *{head}">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-4 control-label">真实姓名</label>

                    <div class="col-sm-4">
                        <input type="text" class="form-control" th:field="*{realName}">
                    </div>
                </div>
            </div>
            <!-- /.box-body -->
            <div class="box-footer">
                <div class="col-sm-4"></div>
                <div class="col-sm-4">
                    <button type="submit" class="btn btn-default">取消</button>
                    <button type="submit" class="btn btn-info pull-right" id="btn_commit">确定</button>
                </div>
            </div>
            <!-- /.box-footer -->
        </form>
    </div>
    <!-- /.box -->
</section>

<!-- jQuery 3 -->
<script th:src="@{/adminlte/bower_components/jquery/dist/jquery.min.js}"></script>
<!-- Bootstrap 3.3.7 -->
<script th:src="@{/adminlte/bower_components/bootstrap/dist/js/bootstrap.min.js}"></script>
<!-- FastClick -->
<script th:src="@{/adminlte/bower_components/fastclick/lib/fastclick.js}"></script>
<!-- AdminLTE App -->
<script th:src="@{/adminlte/js/adminlte.min.js}"></script>
<!-- AdminLTE for demo purposes -->
<script th:src="@{/adminlte/js/demo.js}"></script>
<script th:src="@{/layui/layui.js}"></script>
<script>

    layui.use('upload', function(){
        var upload = layui.upload;
        var files;
        //执行实例
        var uploadInst = upload.render({
            elem: '#img' //绑定元素
            ,auto: false /* 是否选完图片自动上传*/
            ,bindAction: 'btn_commit'
            ,choose: function (obj) {  //选择图片后事件
                //将每次选择的文件追加到文件队列
                files = obj.pushFile();

                //预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
                obj.preview(function (index, file, result) {
                    // console.log(index); //得到文件索引
                    // console.log(file); //得到文件对象
                    // console.log(result); //得到文件base64编码，比如图片
                    $('#img').html('<img style=\'width: 300px;\' src="' + result + '" alt="' + file.name + '" class="layui-upload-img">');
                    //obj.resetFile(index, file, '123.jpg'); //重命名文件名，layui 2.3.0 开始新增

                    //这里还可以做一些 append 文件列表 DOM 的操作

                    //obj.upload(index, file); //对上传失败的单个文件重新上传，一般在某个事件中使用
                    //delete files[index]; //删除列表中对应的文件，一般在某个事件中使用
                });
            }
            , error: function () {
                $("#layui-layer100001").remove();
                layer.msg('上传失败，请重试', {time: 1000}, function () {
                });
                //请求异常回调
                //当上传失败时，你可以生成一个“重新上传”的按钮，点击该按钮时，执行 upload() 方法即可实现重新上传
            }
        });
    });
</script>
</body>
</html>